﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Practices.EnterpriseLibrary.Data;
using Enterprise.DataFactory;
using Enterprise.Model.User;
using Enterprise.Infrastructure;
namespace Enterprise.Data.User
{
    /// <summary>
    ///  用户数据表操作类
    /// </summary>
    public class UserData
    {
        /// <summary>
        ///  用户数据列表
        /// </summary>
        /// <returns></returns>
        public List<UserEntity> UserList()
        {
            List<UserEntity> list = new List<UserEntity>();
            string cmd = "Select * from SYS_USER";
            IDataReader dr = DbExecute.DataReader(cmd);
            while (dr.Read())
            {
                UserEntity entity = new UserEntity();
                if (!Convert.IsDBNull(dr["USERID"])) entity.USERID = Convert.ToInt32(dr["USERID"]);
                if (!Convert.IsDBNull(dr["DEPTID"])) entity.DEPTID = Convert.ToInt32(dr["DEPTID"]);
                if (!Convert.IsDBNull(dr["ULOGINNAME"])) entity.ULOGINNAME = Convert.ToString(dr["ULOGINNAME"]);
                if (!Convert.IsDBNull(dr["ULOGINPASS"])) entity.ULOGINPASS = Convert.ToString(dr["ULOGINPASS"]);
                if (!Convert.IsDBNull(dr["UNAME"])) entity.UNAME = Convert.ToString(dr["UNAME"]);
                if (!Convert.IsDBNull(dr["USEX"])) entity.USEX = Convert.ToString(dr["USEX"]);
                if (!Convert.IsDBNull(dr["UBIRTHDAY"])) entity.UBIRTHDAY = Convert.ToDateTime(dr["UBIRTHDAY"]);
                if (!Convert.IsDBNull(dr["UHWPHONE"])) entity.UHWPHONE = Convert.ToString(dr["UHWPHONE"]);
                if (!Convert.IsDBNull(dr["UGNPHONE"])) entity.UGNPHONE = Convert.ToString(dr["UGNPHONE"]);
                if (!Convert.IsDBNull(dr["SIPCEMAIL"])) entity.SIPCEMAIL = Convert.ToString(dr["SIPCEMAIL"]);
                if (!Convert.IsDBNull(dr["OTHEREMAIL"])) entity.OTHEREMAIL = Convert.ToString(dr["OTHEREMAIL"]);
                if (!Convert.IsDBNull(dr["UIP"])) entity.UIP = Convert.ToString(dr["UIP"]);
                if (!Convert.IsDBNull(dr["UADMIN"])) entity.UADMIN = Convert.ToString(dr["UADMIN"]);
                if (!Convert.IsDBNull(dr["USTATUS"])) entity.USTATUS = Convert.ToString(dr["USTATUS"]);
                if (!Convert.IsDBNull(dr["UORDERBY"])) entity.UORDERBY = Convert.ToInt32(dr["UORDERBY"]);
                list.Add(entity);
            }
            dr.Close();
            return list;
        }

        /// <summary>
        /// 用户数据操作方法
        /// </summary>
        /// <param name="cmd"></param>
        public void UserExecute(string cmd)
        {
            DbExecute.Execute(cmd);
        }

        /// <summary>
        /// 返回数据集合
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        public DataSet ExcuteDataSet(string cmd)
        {
            return DbExecute.GetDataSet(cmd);
        }
    }
}
